#include <bits/stdc++.h>
using namespace std;
// 期待总数-瓜子总数是固定的，即s-m=x1+x2+x3++++xn;生气的程度之和=x1^2+x2^2++++xn^2最小，就是当x1=x2=x3=...xn的时候
#define ll long long
const int N = 1e5 + 7;
ll m, n, a[N], ans;

int main()
{
	cin >> m >> n;
	ll sum = 0;

	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	sum -= m;
	sort(a, a + n);
	for (int i = 0; i < n; i++)
	{
		ll w = min(a[i], sum / (n - i));
		ans += w * w;
		sum -= w;
	}
	cout << ans;
	return 0;
}